home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: readLocalDisk.c,v $
- * $Revision: 1.2 $
- * $Date: 1996/05/04 23:51:47 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
- #include "sysdefs.h"
- #include <sys/file.h>
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "disk.h"
- #include "queues.h"
- #include "diskproc_globals.h"
- #include "diskproc_intfuncs.h"
- #include "diskproc_extfuncs.h"
-
- extern char *ShmAddress;
- extern int Fd;
-
- #ifdef DISKPROC_MAKE
- /* see comments below where Shmstruct is used. */
- extern struct shmid_ds Shmstruct;
- #endif DISKPROC_MAKE
-
- void
- readLocalDisk (
-
- register DISKMSG *message
- )
- {
-
- int length;
- int readLength;
- struct iovec ioPageVec[MAX_DISK_IOVEC];
- int i;
-
- SM_ASSERT(LEVEL_1, (Fd != fileno(stdin)));
-
- TRPRINT(TR_DISKRW, TR_LEVEL_1, ("reading at:%d numVectors:%d",
- message->body.offset, message->body.diskVecCount));
-
- /*
- * attempt to seek to the place in the file
- */
- if (lseek(Fd, (int) message->body.offset, L_SET) < 0) {
-
- /*
- * print an error message
- */
- SM_ERROR(TYPE_SYS, errno);
-
- /*
- * reply in the negative
- */
- if (errno == 0) SM_ERROR(TYPE_FATAL, esmINTERNAL);
- message->header.params.out.errno = errno;
- message->diskmagic = DISK_MESSAGE_MAGIC;
- replyDiskMessage(message);
- }
-
- /*
- * Generate the io vec for the read
- */
- SM_ASSERT(LEVEL_3, (message->body.diskVecCount > 0) &&
- (message->body.diskVecCount <= MAX_DISK_IOVEC));
- length = 0;
- for (i = 0; i < message->body.diskVecCount; i++) {
-
- # ifdef DISKPROC_MAKE
- /* Include this check only for the disk process because
- * Shmstruct doesn't exist in the server process. The check
- * is unnecessary in the single process case anyway.
- */
- # if defined(mips) || defined (vax)
- SM_ASSERT(LEVEL_3, ((message->body.diskVec[i].bufIndex < Shmstruct.sm_size) && (message->body.diskVec[i].bufIndex >= 0)) );
- # elif defined(sparc) || defined(_AIX) || defined(hpux) || defined(linux)
- SM_ASSERT(LEVEL_3, ((message->body.diskVec[i].bufIndex < Shmstruct.shm_segsz) && (message->body.diskVec[i].bufIndex >= 0)) );
- # elif !(defined(sparc) || defined(mips) || defined(vax) || defined(_AIX) || defined(hpux) || defined(linux))
- unsupported
- # else
- /* can't put the else part here because ultrix cpp is broken */
- # endif
- # endif DISKPROC_MAKE
-
- ioPageVec[i].iov_base = ShmAddress+(int)message->body.diskVec[i].bufIndex;
- ioPageVec[i].iov_len = (int)message->body.diskVec[i].length;
-
- /* pull the length out of the message */
- length += (int)message->body.diskVec[i].length;
-
- }
-
- /*
- * attempt to read the vector from the disk
- */
- errno = 0;
- if ((readLength = readv(Fd, ioPageVec, message->body.diskVecCount)) < length) {
-
- /*
- * print an error message
- */
- if(errno)
- SM_ERROR(TYPE_SYS, errno);
-
- /*
- * reply in the negative
- */
- if (errno == 0) SM_ERROR(TYPE_FATAL, esmINTERNAL);
- message->header.params.out.errno = errno;
- message->diskmagic = DISK_MESSAGE_MAGIC;
- replyDiskMessage(message);
-
- } else {
-
- TRPRINT(TR_DISKRW, TR_LEVEL_2, ("read successful:%d bytes", length));
-
- /*
- * reply in the positive
- */
- message->header.params.out.errno = esmNOERROR;
- message->diskmagic = DISK_MESSAGE_MAGIC;
- replyDiskMessage(message);
- }
- }
-